﻿using HardcoreGame.Content.Items.Accessories;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.GameContent.ItemDropRules;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.NPCs.Enemies.Biomesa.Desert
{
    public class DesertTortoise : ModNPC
    {
        public override void SetStaticDefaults()
        {
            Main.npcFrameCount[Type] = 8;
        }
        public override void SetDefaults()
        {
            NPC.npcSlots = 2f;
            NPC.width = 46;
            NPC.height = 32;
            NPC.aiStyle = 39;
            NPC.damage = 80;
            NPC.defense = 30;
            NPC.lifeMax = 470;
            NPC.HitSound = SoundID.NPCHit24;
            NPC.knockBackResist = 0.3f;
            NPC.DeathSound = SoundID.NPCDeath27;
            NPC.value = 500f;
            NPC.noGravity = false;
            AIType = 153;
        }
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.UndergroundDesert,
                new FlavorTextBestiaryInfoElement("Mods.HardcoreGame.NPCs.DesertTortoise.Bestiary")
            ]);
        }
        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            if (spawnInfo.Player.ZoneUndergroundDesert && spawnInfo.SpawnTileY < Main.worldSurface && Main.hardMode)
            {
                return 0.05f;
            }
            return 0f;
        }
        public override void HitEffect(NPC.HitInfo hit)
        {
            if (NPC.life > 0)
            {
                for (int num439 = 0; num439 < hit.Damage / (double)NPC.lifeMax * 30.0; num439++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Sand, hit.HitDirection, -1f);
                }
                return;
            }
            for (int num440 = 0; num440 < 15; num440++)
            {
                Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Sand, 2 * hit.HitDirection, -2f);
            }
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_2").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_3").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_4").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_4").Type);
        }
        public override void ModifyNPCLoot(NPCLoot npcLoot)
        {
            npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<DesertTurtleShell>(), 50, 1));
        }
    }
}
